package gui_demo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Objects;

public class Gui_demo {

    public static void gui(){
        //窗体
        //private addactionlister lister =null;

        JFrame frame = new JFrame("Empty-Chat");
        frame.setSize(426,335);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation((int)(screenSize.getWidth()/2.5),(int)(screenSize.getHeight()/2.5));
        frame.setLayout(new BorderLayout());
        frame.setUndecorated(true);
        frame.setResizable(false);
        frame.setVisible(true);

        //组件及设置
        JLabel label1 = new JLabel(new ImageIcon("code/img/back.jpg"));

        JLabel label2 = new JLabel(new ImageIcon("code/img/qq.jpg"));
        JComboBox comboBox = new JComboBox();
        String[] qq = {"12345","23456","345567","45678"};
        for (int i=0;i<4;i++){
            comboBox.addItem(qq[i]);
        }
        comboBox.setEditable(true);
        JPasswordField passwordField = new JPasswordField(15);
        JLabel label3 = new JLabel("注册账号");
        label3.setForeground(new Color(0x66CCFF));
        JLabel label4 = new JLabel("找回密码");
        label4.setForeground(new Color(0x66CCFF));
        JCheckBox checkbox1 = new JCheckBox("记住密码");
        JCheckBox checkbox2 = new JCheckBox("自动登录");

        JButton button1 = new JButton(new ImageIcon("code/img/close_normal.jpg"));//退出键
        button1.setBounds(403,0,26,26);
        button1.setFocusPainted(false);
        button1.setBorderPainted(false);
        button1.setRolloverIcon(new ImageIcon("code/img/close_hover.jpg"));

        JButton button2 = new JButton(new ImageIcon("code/img/single_normal.jpg"));//新用户
        button2.setPreferredSize(new Dimension(40,40));//设置首选大小
        button2.setFocusPainted(false);//设置点击后焦点不显示
        button2.setRolloverIcon(new ImageIcon("code/img/single_down.jpg"));//设置鼠标移动到此处时控件的样子
        button2.setBorderPainted(false);//设置边框不显示
        button2.setContentAreaFilled(false);//设置不显示按钮背景
        button2.setBounds(0, 10, 40, 40);

        JButton button3 = new JButton("登     录",new ImageIcon("code/img/login_normal.jpg"));//登录键
        //button2.setPreferredSize(new Dimension(40,40));//设置首选大小
        button3.setFont(new Font("宋体", Font.BOLD, 15));
        button3.setHorizontalTextPosition(SwingConstants.CENTER);//将文字放在中间
        button3.setFocusPainted(false);//设置点击后焦点不显示
        button3.setRolloverIcon(new ImageIcon("code/img/login_hover.jpg"));//设置鼠标移动到此处时控件的样子
        button3.setBorderPainted(false);//设置边框不显示
        button3.setContentAreaFilled(false);//设置不显示按钮背景
        button2.setBounds(130, 0, 170, 40);

        JButton button4 = new JButton(new ImageIcon("code/img/right_normal.jpg"));//二维码
        //button4.setPreferredSize(new Dimension(40,40));//设置首选大小
        button4.setRolloverIcon(new ImageIcon("code/img/right_hover.jpg"));//设置鼠标移动到此处时控件的样子
        button4.setFocusPainted(false);//设置点击后焦点不显示
        button4.setBorderPainted(false);//设置边框不显示
        button4.setContentAreaFilled(false);//设置不显示按钮背景
        button4.setBounds(384, 10, 40, 40);


        //面板
        JPanel panel1 = new JPanel();
        JPanel panel1_1 = new JPanel();
        JPanel panel2 = new JPanel();
        Box box1 = Box.createVerticalBox();
        Box box2 = Box.createVerticalBox();
        Box box3 = Box.createVerticalBox();

        //布局

        frame.add(button1);

        panel1_1.add(checkbox1);
        panel1_1.add(checkbox2);
        panel1_1.setVisible(true);

        box2.add(Box.createVerticalStrut(6));
        box2.add(comboBox);
        box2.add(Box.createVerticalStrut(6));
        box2.add(passwordField);

        box3.add(label3);
        box3.add(Box.createVerticalStrut(10));
        box3.add(label4);

        box1.add(box2);
        //box1.add(Box.createVerticalStrut(10));
        box1.add(panel1_1);

        panel1.add(label2);
        panel1.add(Box.createHorizontalStrut(10));
        panel1.add(box1);
        panel1.add(Box.createHorizontalStrut(10));
        panel1.add(box3);
        panel1.setVisible(true);

        panel2.add(button2);
        panel2.add(Box.createHorizontalStrut(10));
        panel2.add(button3);
        panel2.add(Box.createHorizontalStrut(10));
        panel2.add(button4);
        panel2.setVisible(true);

        frame.add(label1,BorderLayout.NORTH);
        frame.add(panel1,BorderLayout.CENTER);
        frame.add(panel2,BorderLayout.SOUTH);

        //临时功能

        button1.addActionListener(e ->System.exit(0));
        button2.addActionListener(e -> {
            JOptionPane.showMessageDialog(frame, "咕咕咕");
        });

        button3.addActionListener(e -> {
            String name = "23333";
            String password = "2333";
            if (name.equals(comboBox.getSelectedItem()) &&(new String(passwordField.getPassword())).equals(password)){

                JFrame frame2 = new JFrame();
                JPanel panel3 = new JPanel();

                ImageIcon img=new ImageIcon("code/img/qqSuccess.jpg");
                JLabel label5 =new JLabel(img);
                label5.setBounds(0, 0, img.getIconWidth(),img.getIconHeight());

                frame2.setUndecorated(true);
                frame2.setSize(img.getIconWidth(),img.getIconHeight());
                frame2.setLocation((int)(screenSize.getWidth()/2.5),(int)(screenSize.getHeight()/4));

                panel3.setLayout(null);
                panel3.setPreferredSize(new Dimension(0,140));

                JButton button5 = new JButton(new ImageIcon("code/img/close2_normal.jpg"));//退出键
                button5.setBounds(img.getIconWidth()-28,0,28,28);
                button5.setFocusPainted(false);
                button5.setBorderPainted(false);
                button5.setRolloverIcon(new ImageIcon("code/img/close2_hover.jpg"));
                button5.addActionListener(e1 -> System.exit(0));

                panel3.setVisible(true);
                panel3.add(label5);
                panel3.add(button5);

                frame2.add(panel3);
                frame.setVisible(false);
                frame2.setVisible(true);
            }
            else {
                JFrame frame3 = new JFrame();
                JPanel panel4 = new JPanel();

                ImageIcon img=new ImageIcon("code/img/error.jpg");
                JLabel label5 =new JLabel(img);
                label5.setBounds(0, 0, img.getIconWidth(),img.getIconHeight());

                frame3.setUndecorated(true);
                frame3.setSize(img.getIconWidth(),img.getIconHeight());
                frame3.setLocation((int)(screenSize.getWidth()/2.5),(int)(screenSize.getHeight()/4));

                panel4.setLayout(null);
                panel4.setPreferredSize(new Dimension(0,140));

                JButton button5 = new JButton(new ImageIcon("code/img/close2_normal.jpg"));//退出键
                button5.setBounds(img.getIconWidth()-28,0,28,28);
                button5.setFocusPainted(false);
                button5.setBorderPainted(false);
                button5.setRolloverIcon(new ImageIcon("code/img/close2_hover.jpg"));
                button5.addActionListener(e1 -> System.exit(0));

                panel4.setVisible(true);
                panel4.add(label5);
                panel4.add(button5);

                frame3.add(panel4);
                frame.setVisible(false);
                frame3.setVisible(true);
            }


        });


        button4.addActionListener(e -> {
            JOptionPane.showMessageDialog(frame, "咕咕咕");
        });


    }
}
